package www.Zheng;

import java.io.*;

/**
 * @Title: Demo10
 * @Author 郑雨杭
 * @Package www.Zheng
 * @Date 2024/7/9 19:04
 * @description: 复制图片
 */
public class Demo10 {
    public static void main(String[] args) {
        File sou = new File("D:\\gitee仓库\\java\\File\\source", "test.jpg");
        File goal = new File("D:\\gitee仓库\\java\\File\\goal" , "goal.jpg");
        OutputStream outputStream = null;
        InputStream inputStream = null;
        try {
            outputStream = new FileOutputStream(goal);
            inputStream = new FileInputStream(sou);
            byte[] rem = new byte[1024];
            if(!goal.exists()){
                goal.createNewFile();
            }
            if(sou.isFile() && goal.isFile()){
                while (true){
                    int i = inputStream.read(rem);
                    if(i==-1){
                        outputStream.flush();
                        break;
                    }else{
                        outputStream.write(rem,0,i);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                outputStream.close();
                inputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
